import { DialogTable } from 'custom/index'
import { getPerformancePage } from '../api'
import ReceptionVolumeColumn from '../component/ReceptionVolumeColumn.vue'
import ConversionRateColumn from '../component/ConversionRateColumn.vue'
import ResponseTimeColumn from '../component/ResponseTimeColumn.vue'
import PerformanceDetailColumn from '../component/PerformanceDetailColumn.vue'

const getParams = ctx => {
  const { props } = ctx
  const row = ctx.ctx.attrs.row || {}
  return {
    url: 'DataQueryAnalysis2Detail',
    condition: { shopId: row.shopId, dateStart: row.dateStart, dateEnd: row.dateEnd, keyword: '' },
    sort: props.sort
  }
}

const performanceDetailDialog = new DialogTable('DialogTable')

performanceDetailDialog
  .title('详情')
  .width('50%')
  .api((data, row) => {
    return getPerformancePage({
      ...data,
      condition: { shopId: row.shopId, dateStart: row.dateStart, dateEnd: row.dateEnd, keyword: '' }
    })
  })
  .useSearch().upto('DialogTable')
  .useAuthButton()
    .useItem('').content('导出').exportExcel(getParams).end()
  .upto('DialogTable')
  .useTable()
    .addIndexColumn()
    .useColumn('date').label('服务日期').minWidth(140).end()
    .useColumn('salesRevenue').label('销售额').minWidth(140).end()
    .useCustomColumn(ReceptionVolumeColumn, 'receptionVolume').label('接待量').minWidth(140).end()
    .useCustomColumn(ConversionRateColumn, 'conversionRate').label('转化率').minWidth(140).end()
    .useCustomColumn(ResponseTimeColumn, 'responseTime').label('响应时间').minWidth(140).end()
    .useColumn('qaratio').label('问答比').percent().minWidth(140).end()
    .useColumn('responseRate').label('回复率').percent().minWidth(140).end()
    .useCustomColumn(PerformanceDetailColumn, 'action').label('详情').width(80).fixed('right').end()
    .upto('DialogTable')
  .usePagination()
    .upto('DialogTable')

const detailDetailDialog = new DialogTable('DialogTable')

detailDetailDialog
  .title('详情')
  .width('60%')
  .api((data, row) => {
    return getPerformancePage({
      ...data,
      condition: { shopId: row.shopId, dateStart: row.dateStart, dateEnd: row.dateEnd, keyword: '', date: row.date }
    })
  })
  .useTable()
    .addIndexColumn()
    .useColumn('accountNo').label('子账号').minWidth(140).end()
    .useColumn('accountName').label('子账号名称').minWidth(140).end()
    .useColumn('salesRevenue').label('销售额').minWidth(140).end()
    .useCustomColumn(ReceptionVolumeColumn, 'receptionVolume').label('接待量').minWidth(140).end()
    .useCustomColumn(ConversionRateColumn, 'conversionRate').label('转化率').minWidth(140).end()
    .useCustomColumn(ResponseTimeColumn, 'responseTime').label('响应时间').minWidth(140).end()
    .useColumn('qaratio').label('问答比').percent().minWidth(140).end()
    .useColumn('responseRate').label('回复率').percent().minWidth(140).end()
    .upto('DialogTable')
  .usePagination()
    .upto('DialogTable')

export default performanceDetailDialog

export {
  detailDetailDialog
}
